package com.zjp.birthdaymanager.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zjp.birthdaymanager.R;
import com.zjp.birthdaymanager.been.BirthInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/23.
 */
public class BirthAdapter extends BaseAdapter {
    private List<BirthInfo> mListBirthInfo = new ArrayList<>();
    private Context mContext;

    public BirthAdapter(Context context){
        this.mContext = context;
    }

    public void setmListBirthInfo(List<BirthInfo> mListBirthInfo) {
        this.mListBirthInfo = mListBirthInfo;
    }

    @Override
    public int getCount() {
        return mListBirthInfo.size();
    }

    @Override
    public Object getItem(int position) {

        return mListBirthInfo.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Holder holder;
        if (convertView==null){
            holder = new Holder();
            convertView = View.inflate(mContext, R.layout.birth_item,null);
            holder.birthPer = (TextView) convertView.findViewById(R.id.tv_birthPer);
            holder.birthDate = (TextView) convertView.findViewById(R.id.tv_birthdate);
            holder.timeDistance = (TextView) convertView.findViewById(R.id.tv_timedistance);
            convertView.setTag(holder);
        }else{
            holder = (Holder) convertView.getTag();
        }
        holder.birthPer.setText(mListBirthInfo.get(position).strName);
        holder.birthDate.setText(mListBirthInfo.get(position).strBirthdate);

        return convertView;
    }

    class Holder{

        TextView birthPer;
        TextView birthDate;
        TextView timeDistance;
    }
}

